//
//  assetsOrderComViewController.m
//  DBAChain
//
//  Created by Mxionlly on 2018/9/7.
//  Copyright © 2018年 Evan. All rights reserved.
//

#import "assetsOrderComViewController.h"
#import "AssetsOrderOverTableViewCell.h"
#import "CommonData.h"
#import "JiaoYiPageDetailViewController.h"
#import "dataOrderBuyAndSaleInfo.h"
#import "taskOverviewService.h"

@interface assetsOrderComViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)    UITableView *tableView;
@property (nonatomic,assign)NSInteger      page;
@property (nonatomic,strong)    NSArray<dataOrderDetailsInfo *> *  orderList;
@end

@implementation assetsOrderComViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.tableView];
    [self loadOrder:1];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    self.hidesBottomBarWhenPushed = NO;
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBar.hidden = NO;
    [self setBlackStatus:YES];
}
-(void)loadData{
    self.page = 1;
    [self loadOrder:1];
}

-(void)loadMoreData{
    self.page ++;
    [self loadOrder:self.page];
}

-(void)loadOrder:(NSInteger) pageIndex{
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setField:[NSString stringWithFormat:@"%ld",self.page] value:@"page"];
    [dict setField:@"10" value:@"pageSize"];
    [dict setField:@"2" value:@"orderType"];//0交易中1已完成2申诉中
    [dict setValue:[UserCenter shareCenter].user.userNo forKey:@"userNo"];
    [taskOverviewService getOrderDetails:dict success:^(dataOrderDetails *response, BOOL success) {
        [DKProgressHUD dismiss];
        if (success) {
            self.orderList = response.orderList;
            [self.tableView reloadData];
            return ;
        }
        [DKProgressHUD showErrorWithStatus:response.statusDesc];
    } failture:^(NSError *error, NSString *strDescription) {
        [DKProgressHUD dismiss];
        [DKProgressHUD showErrorWithStatus:strDescription];
    }];
}

-(UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight-64) style:UITableViewStyleGrouped];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.backgroundColor  = COLOR_Background;
    }
    return _tableView;
}

-(NSInteger )numberOfSectionsInTableView:(UITableView *)tableView{
    return 10;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 120;
}

-(CGFloat )tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return .00001;
}

-(CGFloat )tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AssetsOrderOverTableViewCell *cell = [AssetsOrderOverTableViewCell cellWithTableView:tableView IndexPath:indexPath];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.navigationController pushViewController:[JiaoYiPageDetailViewController new] animated:YES];
}
@end
